package com.tarena.lbs.user.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.user.pojo.param.AdminParam;
import com.tarena.lbs.user.pojo.query.AdminQuery;
import com.tarena.lbs.user.pojo.vo.AdminVO;
import com.tarena.lbs.user.service.AdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 处理和后台用户相关的业务接口
 */

@Slf4j
@Api(tags = "后台用户管理")
@RestController
public class AdminController {
    @Autowired
    private AdminService adminService;

    @ApiOperation("用户详情")
    @GetMapping("/admin/basic/role/detail")
    public Result<AdminVO> detail() throws BusinessException {
        AdminVO adminVO = adminService.detail();
        return new Result<>(adminVO);
    }

    //查询后台管理的 账号列表
    @ApiOperation("账号列表")
    @PostMapping("/admin/basic/role/list")
    public Result<PageResult<AdminVO>> pageList(@RequestBody AdminQuery query)
            throws BusinessException {
        PageResult<AdminVO> voPage= adminService.pageList(query);
        return new Result<>(voPage);
    }

    @ApiOperation("账号保存")
    @PostMapping("/admin/basic/role/add")
    public Result<Void> save(@RequestBody AdminParam param)
            throws BusinessException {
        adminService.save(param);
        return Result.success();
    }


}
